In [24]:
%pylab inline
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
try:
from future.builtins import (bytes, str, open, super, range,
zip, round, input, int, pow, object)
except:
pass
# ---- Standard Libraries not included in pylab
import collections
import glob
import json
import random
import time
from StringIO import StringIO
# ---- Extra Libraries for additional functionality
import elasticsearch
from elasticsearch import Elasticsearch
es = Elasticsearch(['http://search-01.ec2.internal:9200'])
In [25]:
mapping = es.indices.get_mapping("gsod")
obs_mapping = collections.OrderedDict(mapping['gsod']['mappings']['observation']['properties'])
for ob_params in obs_mapping:
print("{:18s}{}".format(ob_params, obs_mapping[ob_params]))
In [26]:
%%bash
curl -XPUT 'http://search-01.ec2.internal:9200/gsod_1929'
curl -XPUT 'http://search-01.ec2.internal:9200/gsod_1929/_mapping/observation' -d '
{
"observation": {
"properties": {
"Num of Obs": {"type": "integer"},
"Wind Speed": {"type": "float"},
"FRSHTT": {"type": "string"},
"Snow Depth": {"type": "float"},
"Gust": {"type": "float"},
"SLP": {"type": "float"},
"Mean Temp": {"type": "float"},
"Max Wind Speed": {"type": "float"},
"Max Temp": {"type": "float"},
"STP": {"type": "float"},
"Min Temp": {"type": "float"},
"WBAN": {"type": "string"},
"Date": {"type": "date", "format": "dateOptionalTime"},
"Station Id": {"type": "string"},
"Dew Point": {"type": "float"},
"Precipitation": {"type": "float"},
"Visibility": {"type": "float"}
}
}
}'
In [27]:
mapping = es.indices.get_mapping("gsod_1929")
obs_mapping = collections.OrderedDict(mapping['gsod_1929']['mappings']['observation']['properties'])
for ob_params in obs_mapping:
print("{:18s}{}".format(ob_params, obs_mapping[ob_params]))
In [10]:
# This is an example of deleting an index
# %%bash
# curl -XDELETE 'http://search-01.ec2.internal:9200/gsod_1929'
In [63]:
query = json.dumps({
"query": {
"match": {
"Mean Temp": "89.3"
}
},
"_source": "Max Temp",
"size": num_of_returns
})
es.search(index="gsod", body=query)
Out[63]:
In [2]:
import es_gsod
gsod = es_gsod.ESGsod()
gsod.search_by_date("1970-09-24", "1970-09-25", 2, "Mean Temp")
Out[2]: